<div class="layui-inline">
  <button type="button" class="layui-btn" id="test-upload-excel">导入兑换码</button>
  <a href="javascript:;" class="layui-btn layui-btn-normal" id="xzmb">下载模板</a>
</div>
<table id="LAY-salecode-manage" lay-filter="LAY-salecode-manage"></table>
<script type="text/html" id="scstatusTpl">
{{# if(d.member_id==0){ }}
<span class="layui-badge layui-bg-black">未使用</span>
{{# }else{ }}
<span class="layui-badge layui-bg-green">已使用</span>
{{# } }}
</script> 
<script type="text/html" id="ctimeTpl"> 
{{# var date = new Date(d.createtime * 1000);
    var dt = date.getFullYear() + '-';
    dt += (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    dt += (Array(2).join(0) + date.getDate()).slice(-2) + ' ';
    dt += (Array(2).join(0) + date.getHours()).slice(-2) + ':';
    dt += (Array(2).join(0) + date.getMinutes()).slice(-2) + ':';
    dt += (Array(2).join(0) + date.getSeconds()).slice(-2); }}
{{ dt }}
</script>
<script type="text/html" id="ptimeTpl"> 
{{# var date = new Date(d.updatetime * 1000);
    var dt = date.getFullYear() + '-';
    dt += (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    dt += (Array(2).join(0) + date.getDate()).slice(-2) + ' ';
    dt += (Array(2).join(0) + date.getHours()).slice(-2) + ':';
    dt += (Array(2).join(0) + date.getMinutes()).slice(-2) + ':';
    dt += (Array(2).join(0) + date.getSeconds()).slice(-2); }}
{{ dt }}
</script>
<script>
layui.use('salecode', layui.factory('salecode')).use(['admin', 'salecode', 'table', 'upload'], function(){
  var $ = layui.$
  ,admin = layui.admin
  ,view = layui.view
  ,table = layui.table
  ,form = layui.form
  ,upload = layui.upload;

  upload.render({
      elem: '#test-upload-excel'
      ,url: layui.setter.baseUrl+'sale/importcode?id='+layui.sale_id
      ,accept: 'file' //普通文件
      ,done: function(res){
        console.log(res);
        layer.msg(res.msg);
        if(res.code == 0){
          layui.table.reload('LAY-salecode-manage');
        }
      }
  });

  $('#xzmb').on('click', function(){
    $(this).attr('href', layui.setter.uploadUrl+'salecode.xls');
  });
});
</script>